<%--
  Created by IntelliJ IDEA.
  User: User
  Date: 2020/10/23
  Time: 12:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>欢迎页</title>
    <script src="${pageContext.request.contextPath}/js/jquery-1.8.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/echarts.min.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/layui/layui.js"></script>
</head>
<style>
    #left {
        width: 58%;
        height: 450px;
        float: left;
    }

    #refresh {
        float: left;
        width: 2%;
    }

    #right {
        width: 40%;
        height: 450px;
        float: right;
    }
</style>
<body>
<%--刷新按钮--%>
<p onclick="refresh()" class="layui-icon layui-icon-refresh layui-anim layui-anim-scaleSpring"></p>

<%--搜索条件表单--%>
<form class="layui-form" id="searchForm">
    <div class="layui-inline"> <!-- 注意：这一层元素并不是必须的 -->
        <div class="layui-inline">
            <div class="layui-input-inline" style="width: 100px;">
                <input type="text" name="year" id="year" placeholder="年份" class="layui-input">
            </div>
            <label class="layui-form-label">范围</label>
            <div class="layui-input-inline" style="width: 100px;">
                <input type="text" name="monthMin" id="month1" placeholder="起始月" autocomplete="off"
                       class="layui-input">
            </div>
            <div class="layui-form-mid">-</div>
            <div class="layui-input-inline" style="width: 100px;">
                <input type="text" name="monthMax" id="month2" placeholder="结束月" autocomplete="off"
                       class="layui-input">
            </div>
            <div class="layui-input-inline" style="width: 50px;">
                <button type="button" onclick="getData()"
                        class="layui-btn layui-btn-sm layui-btn-radius layui-btn-normal">搜索
                </button>
            </div>
            <div class="layui-input-inline" style="width: 50px;">
                <button type="reset" onclick="refresh()" class="layui-btn layui-btn-sm layui-btn-radius layui-btn-primary">重置
                </button>
            </div>
        </div>
    </div>
</form>

<!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
<div id="left"></div>
<div id="right"></div>

</body>
<script type="text/javascript">

    $(function (){
        getData();
    })

    // 页面刷新按钮
    function refresh(){
        $("#searchForm")[0].reset()
        getData();
    }

    // 基于准备好的dom，初始化echarts实例
    var ruKuCount =[];
    var monthData =[];
    var ckCount =[];
    function getData(){
        $.ajax({
            url: '${pageContext.request.contextPath}/ruku/getRuKuMoney',
            type: 'post',
            data: $("#searchForm").serialize(),
            async: false,
            dataType: 'JSON',
            success: function (result) {
                ruKuCount =result.ruKuCount;
                monthData = result.monthData;
                ckCount = result.ckCount;

                begin();
            }
        })
    }

    function begin() {
        var myChart = echarts.init(document.getElementById('left'));

        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '近一年入库出库的设施数量'
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'cross',
                    label: {
                        backgroundColor: '#6a7985'
                    }
                }
            },
            legend: {
                data: ['入库设施数量','出库设施数量']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    boundaryGap: false,
                    data: monthData
                }
            ],
            yAxis: [
                {
                    type: 'value'
                }
            ],
            series: [
                {
                    name: '入库设施数量',
                    type: 'line',
                    stack: '总量',
                    areaStyle: {},
                    data: ruKuCount
                },
                {
                    name: '出库设施数量',
                    type: 'line',
                    stack: '总量',
                    areaStyle: {},
                    data: ckCount
                },
            ]
        };
        myChart.setOption(option)

        var sdata = []
        $.ajax({
            url: '${pageContext.request.contextPath}/ruku/getAllTypeAndCount',
            type: 'post',
            async: false,
            dataType: 'json',
            success: function (result) {

                sdata = result;
            }
        })
        // 基于准备好的dom，初始化echarts实例
        var myChart2 = echarts.init(document.getElementById('right'));
        var option2 = {
            backgroundColor: '#3e4c5a',

            title: {
                text: '仓库中各种类设施数量和比例',
                left: 'center',
                top: 20,

            },

            tooltip: {
                trigger: 'item',
                formatter: '{a} <br/>{b} : {c} ({d}%)'
            },

            visualMap: {
                show: false,
                min: 1500,
                max: 3000,
                inRange: {
                    colorLightness: [0, 1]
                }
            },
            series: [
                {
                    name: '设施类型 ',
                    type: 'pie',
                    radius: '55%',
                    center: ['50%', '50%'],
                    data: sdata,
                    roseType: 'radius',

                    labelLine: {
                        smooth: 0.2,
                        length: 10,
                        length2: 20
                    },

                    animationType: 'scale',
                    animationEasing: 'elasticOut',
                    animationDelay: function (idx) {
                        return Math.random() * 200;
                    }
                }
            ]
        };
        // 使用刚指定的配置项和数据显示图表。
        myChart2.setOption(option2);
    }

</script>

<%--时间选择器--%>
<script>
    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#year' //指定元素
            , type: 'year'
            , calendar: true
        });
        laydate.render({
            elem: '#month1' //指定元素
            , format: 'MM'
            , type: 'month'
            , calendar: true
        });
        laydate.render({
            elem: '#month2' //指定元素
            , format: 'MM'
            , type: 'month'
            , calendar: true
        });
    });
</script>
</html>
